Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Imports DotNetNuke.Common.Globals
Imports DotNetNuke.Services.Exceptions.Exceptions
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Entities.Tabs
Imports DotNetNuke.Security

Namespace Avastone.DNN.Modules.HouseIndex

    Public Class HouseIndexOptions
        Inherits ModuleSettingsBase

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Protected WithEvents chkShowHidden As System.Web.UI.WebControls.CheckBox
        Protected WithEvents chkShowAdmin As System.Web.UI.WebControls.CheckBox
        Protected WithEvents chkDescriptionsVisible As System.Web.UI.WebControls.CheckBox
        Protected WithEvents txtCssClassPrefix As System.Web.UI.WebControls.TextBox
        Protected WithEvents chkKeywordsVisible As System.Web.UI.WebControls.CheckBox
        Protected WithEvents chkSortByTabName As System.Web.UI.WebControls.CheckBox
        Protected WithEvents chkModulesVisible As System.Web.UI.WebControls.CheckBox

        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region

        Private ShowHidden As Boolean
        Private ShowAdmin As Boolean
        Private DescriptionsVisible As Boolean
        Private KeywordsVisible As Boolean
        Private ModulesVisible As Boolean
        Private SortByTabName As Boolean
        Private CssClassPrefix As String

#Region " Procedures "

        Public Overrides Sub LoadSettings()

            Try
                If Not TabModuleSettings("ShowHidden") Is Nothing Then
                    Me.ShowHidden = Boolean.Parse(TabModuleSettings("ShowHidden").ToString)
                Else
                    Me.ShowHidden = False
                End If

                If Not TabModuleSettings("ShowAdmin") Is Nothing Then
                    Me.ShowAdmin = Boolean.Parse(TabModuleSettings("ShowAdmin").ToString)
                Else
                    Me.ShowAdmin = False
                End If

                If Not TabModuleSettings("DescriptionsVisible") Is Nothing Then
                    Me.DescriptionsVisible = Boolean.Parse(TabModuleSettings("DescriptionsVisible").ToString)
                Else
                    Me.DescriptionsVisible = True
                End If

                If Not TabModuleSettings("KeywordsVisible") Is Nothing Then
                    Me.KeywordsVisible = Boolean.Parse(TabModuleSettings("KeywordsVisible").ToString)
                Else
                    Me.KeywordsVisible = True
                End If

                If Not TabModuleSettings("ModulesVisible") Is Nothing Then
                    Me.ModulesVisible = Boolean.Parse(TabModuleSettings("ModulesVisible").ToString)
                Else
                    Me.ModulesVisible = True
                End If

                If Not TabModuleSettings("SortByTabName") Is Nothing Then
                    Me.SortByTabName = Boolean.Parse(TabModuleSettings("SortByTabName").ToString)
                Else
                    Me.SortByTabName = False
                End If

                If Not TabModuleSettings("CssClassPrefix") Is Nothing Then
                    Me.CssClassPrefix = CType(TabModuleSettings("CssClassPrefix"), String)
                Else
                    Me.CssClassPrefix = ""
                End If

                Me.BindControls()

            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try

        End Sub

        Private Sub BindControls()

            Try
                Me.chkShowHidden.Checked = Me.ShowHidden
                Me.chkShowAdmin.Checked = Me.ShowAdmin
                Me.chkDescriptionsVisible.Checked = Me.DescriptionsVisible
                Me.chkKeywordsVisible.Checked = Me.KeywordsVisible
                Me.chkModulesVisible.Checked = Me.ModulesVisible
                Me.chkSortByTabName.Checked = Me.SortByTabName
                Me.txtCssClassPrefix.Text = Me.CssClassPrefix

            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try

        End Sub

        Public Overrides Sub UpdateSettings()
            Try
                ' Update local values
                Me.ShowHidden = Me.chkShowHidden.Checked
                Me.ShowAdmin = Me.chkShowAdmin.Checked
                Me.DescriptionsVisible = Me.chkDescriptionsVisible.Checked
                Me.KeywordsVisible = Me.chkKeywordsVisible.Checked
                Me.ModulesVisible = Me.chkModulesVisible.Checked
                Me.SortByTabName = Me.chkSortByTabName.Checked
                Me.CssClassPrefix = Me.txtCssClassPrefix.Text

                ' Update stored values
                Dim objModules As New ModuleController
                'objModules.UpdateModuleSetting(ModuleId, "key", value)
                objModules.UpdateTabModuleSetting(TabModuleId, "ShowHidden", Me.ShowHidden.ToString)
                objModules.UpdateTabModuleSetting(TabModuleId, "ShowAdmin", Me.ShowAdmin.ToString)
                objModules.UpdateTabModuleSetting(TabModuleId, "DescriptionsVisible", Me.DescriptionsVisible.ToString)
                objModules.UpdateTabModuleSetting(TabModuleId, "KeywordsVisible", Me.KeywordsVisible.ToString)
                objModules.UpdateTabModuleSetting(TabModuleId, "ModulesVisible", Me.ModulesVisible.ToString)
                objModules.UpdateTabModuleSetting(TabModuleId, "SortByTabName", Me.SortByTabName.ToString)
                objModules.UpdateTabModuleSetting(TabModuleId, "CssClassPrefix", Me.CssClassPrefix)

                ' Redirect back to the portal home page
                Response.Redirect(NavigateURL(), True)
            Catch exc As Exception
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region

    End Class

End Namespace
